<?php
/**
 * Created by PhpStorm.
 *
 * Author : Traveler.
 * Time   : 2020/2/12 18:22
 * Company: Inner Mongolia Zhengzhi Network Technology Co., Ltd
 */

namespace app\admin\validate;


use think\Validate;

class User extends Validate
{
    /**
     * 当前验证规则
     * @var array
     */
    protected $rule = [
        'name'         => 'require',
        'sex'          => 'require|in:0,1',
        'cellphone'    => 'require|mobile|unique:ibms_user',
        'password'     => 'require|min:6|max:16',
        'new_password' => 'require|min:6|max:16|confirm:rep_password',
        'rep_password' => 'require|min:6|max:16',
        'captcha'      => 'require|captcha',
    ];

    /**
     * 验证提示信息
     * @var array
     */
    protected $message = [
        'name' => [
            'require' => '姓名不能为空',
        ],
        'sex' => [
            'require' => '性别不能为空',
            'in'      => '性别错误',
        ],
        'cellphone' => [
            'require' => '手机号码不能为空',
            'mobile'  => '手机号码格式错误',
            'unique'  => '手机号码已存在',
        ],
        'password' => [
            'require' => '密码不能为空',
            'min'     => '密码不能小于6位',
            'max'     => '密码不能大于16位',
        ],
        'new_password' => [
            'require' => '新密码不能为空',
            'min'     => '新密码不能小于6位',
            'max'     => '新密码不能大于16位',
            'confirm' => '新密码两次输入不一致',
        ],
        'rep_password' => [
            'require' => '确认密码不能为空',
            'min'     => '确认密码不能小于6位',
            'max'     => '确认密码不能大于16位',
        ],
        'captcha' => [
            'require' => '验证码不能为空',
            'captcha' => '验证码错误',
        ]
    ];

    // 验证场景：新增用户
    public function sceneAdd()
    {
        return $this->only(['name', 'cellphone', 'sex']);
    }

    // 验证场景：编辑用户
    public function sceneEdit()
    {
        return $this->only(['name', 'cellphone', 'sex']);
    }
}